package ModelLayer;
import java.util.*;

/**
 * Write a description of class ProductLib here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ProductLib
{
    private ArrayList<Product> productLib;
    
    private static ProductLib instance;
    
    private ProductLib()
    {
        productLib = new ArrayList<Product>();
    }
    
    public static ProductLib getProductLib()
    {
        if(instance == null)
        {
            instance = new ProductLib();    
        }
        
        return instance;
    }
    public void addProduct(Product product)
    {
        productLib.add(product);
    }
    public Product getProductByProductId(int _productId)
    {
        Product retProduct = null;
        int index = 0;
        boolean found = false;
        
        while(!found && index < productLib.size())
        {
            Product currProduct = productLib.get(index);
            
            if(currProduct.getProductId() == _productId)
            {
                retProduct = currProduct;
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return retProduct;
    }
}
